var prefix = jsctx + "/withdrawManager";

var withdrawManagerDetail = (function () {
    function init() {
        setTimeout(function () {//防止先于-读取缓存执行
            load();
        }, 10)
    };

    function reset() {
        $("#nickName").val("");
        $("#status").val("");
        $("#beginTime").val("");
        $("#endTime").val('');
        $("#withDrawStatus").val("");
    }

    $('#exampleTable').on('load-success.bs.table', function (e, data) {
        if (data.total && !data.rows.length) {
            $('#exampleTable').bootstrapTable('selectPage').bootstrapTable('refresh');
        }
    });
    var h = $(window).height() - 40;

    // var pageNumber = sessionStorage.getItem("pageNumber",)
    function load() {
        // alert($('#exampleTable').bootstrapTable('getOptions').pageNumber);
        $('#exampleTable')
            .bootstrapTable(
                {
                    method: 'get',
                    url: prefix + "/listWithdrawMagDetailVo",
                    iconSize: 'outline',
                    toolbar: '#exampleToolbar',
                    striped: false,
                    dataType: "json",
                    pagination: true,
                    singleSelect: false,
                    pageSize: 20,
                    pageList: [20],
                    pageNumber: 1,
                    sidePagination: "server",
                    paginationShowPageGo: true,
                    height: h,
                    showColumns: true,
                    queryParams: function (params) {
                        return {
                            limit: params.limit,
                            offset: (params.offset / params.limit) + 1,
                            nickName: $('#nickName').val().trim(),
                            status: $('#status').val().trim(),
                            beginTime: $('#beginTime').val().trim(),
                            endTime: $('#endTime').val().trim(),
                            withDrawStatus: $('#withDrawStatus').val().trim()
                        };
                    },
                    columns: [
                        {
                            title: '#', field: '', width: '50', align: 'left',
                            formatter: function (value, row, index) {
                                return index + 1;
                            }
                        },
                        {field: 'memberId', title: '客户ID', width: '100'},
                        {field: 'nickName', title: '客户名称', width: '100'},
                        {field: 'memberType', title: '客户类型', width: '100'},
                        {
                            field: 'channelType', title: '收益类型', width: '100', align: 'left',
                            formatter: function (value, row, index) {
                                if (row.channelType == '0') {
                                    return '新用户返点'
                                } else if (row.channelType == '1') {
                                    return '复充返点'
                                }
                            }
                        },


                        {field: 'rechargeAmount', title: '充值金额', width: '100'},
                        {field: 'withDrawAmount', title: '提成收益金额', width: '100'},
                        {field: 'channelLevel', title: '等级', width: '50'},
                        {field: 'rabeteRatio', title: '提成比例', width: '100'},
                        {field: 'localTradeNo', title: '流水单号', width: '200'},
                        {field: 'rechargeTime', title: '充值时间', width: '100'},
                        {field: 'memberId2', title: '用户ID', width: '100'},
                        {field: 'mobile2', title: '用户电话', width: '100'},
                        {
                            field: 'channelStatus', title: '审核状态', width: '100', align: 'left',
                            formatter: function (value, row, index) {
                                if (row.channelStatus == '0') {
                                    return '待审核'
                                } else if (row.channelStatus == '1') {
                                    return '审核驳回'
                                }else if (row.channelStatus == '2') {
                                    return '审核通过'
                                }
                            }
                        },
                        {field: 'withDrawTime', title: '可提现时间', width: '100'},
                        // {field: 'channelStatus', title: '是否已提现', width: '100'},
                        {
                            field: 'channelStatus', title: '是否已提现', width: '100', align: 'left',
                            formatter: function (value, row, index) {
                                if (row.channelStatus == '0') {
                                    return '否'
                                } else if (row.channelStatus == '1') {
                                    return '否'
                                }else if (row.channelStatus == '2') {
                                    return '是'
                                }
                            }
                        },
                        {field: 'remark', title: '备注', width: '100'},
                    ]
                });
    }

    function reLoad() {
        $('#exampleTable').bootstrapTable('refresh');
    }

    function goBack() {
        location.href = prefix + "/index";
    }

    function acctTenantOperatorElecStation(tenantOperatorCode) {
        location.href = prefix + "/acctTenantOperatorElecStation/" + tenantOperatorCode;
    }

    function acctBank(tenantOperatorCode) {
        location.href = prefix + "/acctBank/" + tenantOperatorCode;
    }


    function acctBillOrder(tenantOperatorCode) {
        location.href = prefix + "/acctBillOrder/" + tenantOperatorCode;
    }


    function acctDetail(tenantOperatorCode) {
        location.href = prefix + "/acctDetail/" + tenantOperatorCode;
    }

    function acctWithdrawApply() {
        location.href = prefix + "/acctWithdrawApply";
    }

    function exportAcctTenantOperator() {
        $.fileDownload(jsctx + "/tenantOperator/exportTenantOperator", { // 后台请求链接
            httpMethod: "get",　　　　　　　　// 请求方式
            contentType: 'application/json',　 // 请求头
            data: {　　　　　　　　　　　　　　　// 参数，左边为后台接收的参数名，右边为前端获取的值，
                operatorName: $("#operatorName").val().trim(),
                loginName: $("#loginName").val().trim(),
                contactName: $("#contactName").val().trim(),
            },
            prepareCallback: function (url) {
                layer.msg("文件下载中...", {time: -1})
            },
            abortCallback: function (url) {
                // 异常终止
                layer.msg("文件下载异常！！");
            },
            successCallback: function (url) {
                layer.msg("文件下载成功！！", {time: 1500});
            },
            failCallback: function (data) {
                var str = "{" + data.substring(data.indexOf("{") + 1, data.indexOf("}")) + "}";
                layer.msg(JSON.parse(str).message);
            }
        })
    }

    /**
     * 导出列表
     */
    function exportList() {
        $.fileDownload(prefix + "/exportDetail", { // 后台请求链接
            httpMethod: "get",　　　　　　　　// 请求方式
            contentType: 'application/json',　 // 请求头
            data: {　　　　　　　　　　　　　　　// 参数，左边为后台接收的参数名，右边为前端获取的值，
                nickName: $('#nickName').val().trim(),
                status: $('#status').val().trim(),
                beginTime: $('#beginTime').val().trim(),
                endTime: $('#endTime').val().trim(),
                withDrawStatus: $('#withDrawStatus').val().trim(),
                offset: $('.active .page-link').text(),
                limit: $(".page-size").text()
            },
            prepareCallback: function (url) {
                layer.msg("文件下载中...", {time: -1})
            },
            abortCallback: function (url) {
                // 异常终止
                layer.msg("文件下载异常！！");
            },
            successCallback: function (url) {
                layer.msg("文件下载成功！！", {time: 1500});
            },
            failCallback: function (data) {
                var str = "{" + data.substring(data.indexOf("{") + 1, data.indexOf("}")) + "}";
                layer.msg(JSON.parse(str).message);
            }
        })
    }

    return {
        init: init,
        goBack: goBack,
        reLoad: reLoad,
        reset: reset,
        exportList: exportList,
        acctTenantOperatorElecStation: acctTenantOperatorElecStation,
        acctBank: acctBank,
        acctBillOrder: acctBillOrder,
        acctDetail: acctDetail,
        acctWithdrawApply: acctWithdrawApply,
        exportAcctTenantOperator: exportAcctTenantOperator
    };
})();
